<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="85px">
      <el-form-item label="物料名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入物料名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品" prop="productguid">
        <el-select v-model="queryParams.productguid" placeholder="请选择产品" clearable filterable size="small">
          <el-option
            v-for="item in productOptions"
            :key="item.guid"
            :label="item.productname"
            :value="item.guid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产品类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择产品类型" clearable size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="品牌" prop="brandid">
        <el-select v-model="queryParams.brandid" placeholder="请选择品牌" clearable filterable size="small">
          <el-option
            v-for="item in brandOprions"
            :key="item.guid"
            :label="item.name"
            :value="item.guid"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产品标识" prop="flag">
        <el-select v-model="queryParams.flag" placeholder="请选择产品标识" clearable size="small">
          <el-option
            v-for="dict in flagOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="金蝶编码" prop="kingdeenum">
        <el-input
          v-model="queryParams.kingdeenum"
          placeholder="请输入金蝶编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="内部价方式" prop="innerSettlePriceFlag">
        <el-select v-model="queryParams.innerSettlePriceFlag" placeholder="请选择内部价方式" clearable size="small">
          <el-option
            v-for="dict in innerSettlePriceFlags"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="美团编码" prop="mtSkuid">
        <el-input v-model="queryParams.mtSkuid" size="small" clearable placeholder="请输入美团编码" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['product:salesspecification:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:salesspecification:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:salesspecification:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:salesspecification:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="salesspecificationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="产品类型" align="center" prop="type" width="60" :formatter="typeFormat" />
      <el-table-column label="品牌" align="center" prop="brandname" width="100" />
      <el-table-column label="品种" align="center" prop="productname" width="100" />
      <el-table-column label="物料名称" align="center" prop="name" width="160" />
      <el-table-column label="计价方式" align="center" prop="valuation" :formatter="valuationFormat" />
      <el-table-column label="销售单位" align="center" prop="unit" width="60" />
      <el-table-column label="销售单位转换率" align="center" prop="" width="60" />
      <el-table-column label="金蝶编码" align="center" prop="kingdeenum" />
      <el-table-column label="美团编码" align="center" prop="mtSkuid"/>
      <el-table-column label="库存单位" align="center" prop="stockunit" />
      <el-table-column label="内部结算" align="center" width="130" >
        <template slot-scope="scope">
          <span v-if="scope.row.innerSettlePriceFlagName">{{ scope.row.inSettleFlagName + ' | ' + scope.row.innerSettlePriceFlagName }}</span>
          <span v-else>{{ scope.row.inSettleFlagName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="operator" />
      <el-table-column label="创建时间" align="center" prop="createtime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['product:salesspecification:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['product:salesspecification:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改物料管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" append-to-body>
      <el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="125px">
        <el-form-item label="产品类型" prop="type" >
<!--          <el-select v-model="form.type" placeholder="请选择产品类型" size="small" clearable :disabled="form.dataNum">-->
          <el-select v-model="form.type" placeholder="请选择产品类型" size="small" clearable>
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="品牌" prop="brandid">
          <el-select v-model="form.brandid" placeholder="请选择品牌" size="small" clearable filterable>
          <el-option
            v-for="item in brandOprions"
            :key="item.guid"
            :label="item.name"
            :value="item.guid"
          />
        </el-select>
        </el-form-item>
        <el-form-item label="品种" prop="productguid">
<!--          <el-select v-model="form.productguid" placeholder="请选择品种" size="small" clearable  :disabled="form.dataNum">-->
          <el-select v-model="form.productguid" placeholder="请选择品种" size="small" clearable filterable>
            <el-option
              v-for="item in productOptions"
              :key="item.guid"
              :label="item.productname"
              :value="item.guid"
            />
        </el-select>
        </el-form-item>
<!--        <el-form-item label="产品编号" prop="code">-->
<!--          <el-input v-model="form.code"  placeholder="请输入产品编号" size="small" clearable />-->
<!--        </el-form-item>-->
        <el-form-item label="物料名称" prop="name">
<!--          <el-input v-model="form.name" placeholder="请输入物料名称" :disabled="form.dataNum" size="small" clearable />-->
          <el-input v-model="form.name" placeholder="请输入物料名称" size="small" clearable />
        </el-form-item>
        <el-form-item label="销售计价方式" prop="valuation">
          <el-select v-model="form.valuation" placeholder="请选择销售计价方式" size="small" clearable>
            <el-option
              v-for="dict in valuationOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="销售单位" prop="unit">
          <el-select v-model="form.unit" placeholder="请选择销售单位"  size="small" clearable >
            <el-option
              v-for="dict in saleUnitOptions"
              :key="dict.id"
              :label="dict.unitName"
              :value="dict.unitName"
              @click.native="getSfunit($event, dict)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="销售单位转换率" prop="netweight" :rules="rules.netweight">
          <el-input v-model="form.netweight" placeholder="销售单位到库存单位转换率" size="small" clearable />
        </el-form-item>
<!--        <el-form-item label="包装重量" prop="packageweight">-->
<!--          <el-input v-model="form.packageweight" placeholder="请输入包装重量" :disabled="form.dataNum" size="small" clearable/>-->
<!--          <el-input v-model="form.packageweight" placeholder="请输入包装重量" size="small" clearable/>-->
<!--        </el-form-item>-->
<!--         <el-form-item label="赠送(%)" prop="concession">-->
<!--          <el-input v-model="form.concession" placeholder="请输入赠送" size="small" clearable />-->
<!--        </el-form-item>-->
        <el-form-item label="是否套装" prop="flag">
<!--          <el-select v-model="form.flag" placeholder="请选择是否套装"  size="small" clearable  :disabled="form.dataNum">-->
          <el-select v-model="form.flag" placeholder="请选择是否套装"  size="small" clearable >
            <el-option
              v-for="dict in flagOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="金蝶编码" prop="kingdeenum">
          <el-input v-model="form.kingdeenum" placeholder="请输入金蝶编码" size="small" clearable />
        </el-form-item>
        <el-form-item label="金蝶单位" prop="kingdeeunit">
          <el-select v-model="form.kingdeeunitid" placeholder="请选择金蝶单位"  size="small" clearable >
            <el-option
              v-for="dict in unitOptions"
              :key="dict.id"
              :label="dict.unitName"
              :value="parseInt(dict.id)"
              @click.native="getUnitkd($event, dict)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="库存单位" prop="stockunitid">
          <el-select v-model="form.stockunitid" placeholder="请选择库存单位"  size="small" clearable >
            <el-option
              v-for="dict in unitOptions"
              :key="dict.id"
              :label="dict.unitName"
              :value="parseInt(dict.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="基础原料" prop="baseFlag">
          <el-switch v-model="form.baseFlag" active-color="#0DFF00" :active-value='1' :inactive-value='2'>
          </el-switch>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态" size="small" clearable>
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内部结算标识" prop="innerSettleFlag">
          <el-select v-model="form.innerSettleFlag" placeholder="请选择内部结算标识" size="small" clearable>
            <el-option
              v-for="dict in innerSettleFlags"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
          <span style="color: #ccc;"> (不需要内部结算则该物料销售订单的销售组织=库存组织)</span>
        </el-form-item>
        <el-form-item label="内部价方式" prop="innerSettlePriceFlag">
          <el-select v-model="form.innerSettlePriceFlag" placeholder="请选择内部价方式" size="small" clearable>
            <el-option
              v-for="dict in innerSettlePriceFlags"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="固定毛利率" prop="innerSettleFixRate">
          <el-input v-model="form.innerSettleFixRate" placeholder="请输入固定毛利率" size="small" clearable />
        </el-form-item>
        <el-form-item label="固定毛利额" prop="innerSettleFixRateAmt">
          <el-input v-model="form.innerSettleFixRateAmt" placeholder="请输入固定毛利额" size="small" clearable />
        </el-form-item>
        <el-form-item label="美团编码" prop="mtSkuid">
          <el-input v-model="form.mtSkuid" placeholder="请输入美团编码" size="small" clearable/>
        </el-form-item>
        <el-form-item label="美团单位" prop="mtStockunitId" :rules="rules.mtStockunitId">
          <el-select v-model="form.mtStockunitId" placeholder="请选择美团单位" clearable size="small">
            <el-option v-for="dict in mtUnits" :label="dict.unitName" :value="dict.id" :key="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="美团单位转换率" prop="mttostockUnitRate" :rules="rules.mttostockUnitRate">
          <el-input v-model="form.mttostockUnitRate" placeholder="美团到库存单位的转换率" size="small" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSalesspecification, getSalesspecification, delSalesspecification, addSalesspecification, updateSalesspecification, exportSalesspecification } from "@/api/product/salesspecification";
import { findBrandList, findProductList, findStockUnitList } from "@/api/public";
import { trigger } from '@/utils/generator/config'
export default {
  name: "Salesspecification",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      disabled:false,
      disabled1:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料管理表格数据
      salesspecificationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 产品类型字典
      typeOptions: [],
      // 销售计价方式字典
      valuationOptions: [],
      // 状态字典
      statusOptions: [],
      // 产品标识字典
      flagOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        productguid: null,
        type: null,
        status: null,
        brandid: null,
        flag: null,
        kingdeenum: null,
        unitid: null,
        stockunit: null,
        innerSettlePriceFlag: null,
        mtSkuid:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        type: [
          { required: true, message: "产品类型不能为空", trigger: "change" }
        ],
        brandid: [
          { required: true, message: "品牌不能为空", trigger: "change" }
        ],
        productguid: [
          { required: true, message: "品种不能为空", trigger: "change" }
        ],
        name: [
          { required: true, message: "物料名称不能为空", trigger: "blur" }
        ],
        unit: [
          { required: true, message: "销售单位不能为空", trigger: "change" }
        ],
        // netweight: [
        //   { required: true, message: "净重不能为空", trigger: "blur" }
        // ],

        // netweight: [
        //   { required: true, message: "销售单位转换率不能为空", trigger: "blur" },
          // {
          //   validator: (rule, value, callback) => {
          //     if (this.form.valuation == 1 && this.isUnit == 1 && value <= 0) {
          //       callback(new Error('净重有误'));
          //     } else {
          //       callback();
          //     }
          //   },
          //   trigger: 'blur',
          // }
        // ],
        valuation: [
          { required: true, message: "销售计价方式不能为空", trigger: "change" }
        ],
        flag: [
          { required: true, message: "是否套装不能为空", trigger: "change" }
        ],
        stockunitid: [
          { required: true, message: "库存单位不能为空", trigger: "change" }
        ],
        kingdeeunit: [
          { required: true, message: "金蝶单位不能为空", trigger: "blur" }
        ],
        innerSettleFlag: [
          { required: true, message: "内部结算不能为空", trigger: "change" }
        ],
        innerSettlePriceFlag: [
          { required: true, message: "内部价方式不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" },
        ],
        // baseFlag: [
        //   { required: true, message: "基础原料不能为空", trigger: "change" }
        // ],

        // name1:[
        //   {validator:function(rule,value,callback) {
        //     //校验中文的正则表达式 /^[\u4e00-\u9fa5]{0,}$/
        //       if (/^[\u4e00-\u9fa5]{0,}$/.test(value)==false){
        //         callback(new Error("请输入中文！"))
        //       }else {
        //         //校验通过
        //         callback();
        //       }
        //     },trigger:'blur'
        //   }
        // ],
        // phone1:[
        //   {validator:function(rule,value,callback) {
        //     //  校验手机号
        //       if (/^1[34578]\d{9}$/.test(value)==false){
        //         callback(new Error("请输入正确的手机号"))
        //       }else {
        //         //校验通过
        //         callback()
        //       }
        //     },trigger:'blur'
        //   }
        // ],
      },

      brandOprions: [],
      productOptions: [],
      unitOptions: [],
      saleUnitOptions: [],
      isUnit: '',
      stockunitList: [],
      innerSettleFlags: [],
      innerSettlePriceFlags: [],
      mtUnits:[],
    };
  },
  watch: {
    'form.mtStockunitId':function(val, oldVal) {
      this.mtUnits.map(item=>{
        if (item.id==val){
          this.form.mtStockunitName=item.unitName;
        }
      })
    },
    'form.unit':function(val,oldVal) {
      if (val){
        this.rules.netweight=[{required:true,message:"销售单位转换率不能为空",trigger:"blur"}];
      }else {
        this.rules.netweight=[]
      }
    },
    'form.mtSkuid':function(val, oldVal) {
      if (val){
        this.rules.mtStockunitId=[{required:true,message:"美团单位不能为空",trigger:"blur"}];
        this.rules.mttostockUnitRate=[{required:true,message:"转换率不能为空",trigger:"blur"}];
      }else {
        this.rules.mtStockunitId=[];
        this.rules.mttostockUnitRate=[];
      }
    },
    'form.valuation': function(val, oldVal){
      // console.log("val:"+val,"old:"+oldVal);
      if (oldVal) this.form.unit = '';
      //校验销售单位
      if (val == 1) {
        this.saleUnitOptions = this.unitOptions.filter(item => {
          return item.isUnit == 0;
        });
      } else {
        this.saleUnitOptions = this.unitOptions.filter(item => {
          return item.isUnit == 1;
        })
      }
      // //校验单位净重
      // if (val == 1 && this.isUnit == 1) {
      //   this.rules.netweight[0].required = true;
      // } else {
      //   this.rules.netweight[0].required = false;
      // }
    },
    'form.stockunitid': {
      handler:function(val){
        if (!val) return;
        console.log('stockunitidval:', val)
        let item = this.unitOptions.find(item => item.id == val);
        this.form.stockunit = item.unitName;
        this.isUnit = item.isUnit;
        // if (this.form.valuation == 1 && this.isUnit == 1) {
        //   this.rules.netweight[0].required = true;
        // } else {
        //   this.rules.netweight[0].required = false;
        // }
      },
      immediate:true
    },
  },
  created() {
    this.getList();
    this.findBrandList();
    this.findProductList();
    this.findStockUnitList();
    this.getDicts("sp_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("valuation").then(response => {
      this.valuationOptions = response.data;
    });
    this.getDicts("sp_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sp_flag").then(response => {
      this.flagOptions = response.data;
    });
    this.getDicts("multipart_flag").then(response => {
      this.innerSettleFlags = response.data;
    });
    this.getDicts("innerSettlePrice_flag").then(response => {
      this.innerSettlePriceFlags = response.data;
    });
  },
  methods: {
    getUnit(event, item){
      // this.form.stockunit = item.unitName;
      // this.isUnit = item.isUnit;
      // if (this.form.valuation == 1 && this.isUnit == 1) {
      //   this.rules.netweight[0].required = true;
      // } else {
      //   this.rules.netweight[0].required = false;
      // }
    },
    getSfunit(event, item){
      console.log(item)
       this.form.sfunitid = item.id;
    },
    getUnitkd(event, item){
      this.form.kingdeeunit = item.kdunit;
    },
    findBrandList(){
      findBrandList().then(response => {
        this.brandOprions = response.data;
      });
    },
    findProductList(){
      findProductList().then(response => {
        this.productOptions = response.data;
      });
    },
    async findStockUnitList(){
      await findStockUnitList().then(response => {
        this.unitOptions = response.data;
        this.mtUnits=response.data;
      });
    },
    /** 查询物料管理列表 */
    getList() {
      this.loading = true;
      listSalesspecification(this.queryParams).then(response => {
        this.salesspecificationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 产品类型字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 销售计价方式字典翻译
    valuationFormat(row, column) {
      return this.selectDictLabel(this.valuationOptions, row.valuation);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 产品标识字典翻译
    flagFormat(row, column) {
      return this.selectDictLabel(this.flagOptions, row.flag);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        guid: null,
        name: null,
        description: null,
        operatorid: null,
        createtime: null,
        productguid: null,
        sort: null,
        code: null,
        netweight: null,
        packageweight: null,
        type: null,
        concession: null,
        valuation: null,
        status: null,
        operator: null,
        lastupdate: null,
        unit: null,
        brandid: null,
        flag: null,
        kingdeenum: null,
        stockunitid: null,
        stockunit: null,
        dataNum: false,
        kingdeeunitid: null,
        kingdeeunit: null,
        innerSettlePriceFlag: null,
        baseFlag: 2,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.guid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加物料管理";
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      // await this.findStockUnitList();
      this.reset();
      const guid = row.guid || this.ids
      getSalesspecification(guid).then(response => {
        this.form = response.data;
        this.mtUnits.map(item=>{
          if (item.unitName==this.form.mtStockunitName){
            this.form.mtStockunitId=item.id;
          }
        })
        // if (response.data.innerSettlePriceFlag==3){
        //   this.disabled1=true;
        // }
        // if (response.data.innerSettlePriceFlag==4){
        //   this.disabled=true;
        // }

        console.log(response.data);
        this.open = true;
        this.title = "修改物料管理";

      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (!this.form.mtStockunitId){
            this.form.mtStockunitName='';
          }
          // if (this.form.valuation == 1 && this.isUnit == 1 && this.form.netweight <= 0) {
          //   this.msgInfo('净重有误');
          //   return;
          // }
          if (this.form.guid != null) {
            //sfunitid为空的情况下提交sfunitid
            if (!this.form.sfunitid) {
              this.form.sfunitid = (this.unitOptions.filter(item => {
                return item.unitName == this.form.unit;
              })[0] || {}).id;
            }
            updateSalesspecification(this.form).then(response => {
              console.log(this.from);
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSalesspecification(this.form).then(response => {
              this.msgSuccess("新增成功");
              // this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const guids = row.guid || this.ids;
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSalesspecification(guids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有物料管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSalesspecification(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
